package com.demo.mvp.presenter;

import com.demo.ioc.IocContainer;
import com.demo.mvp.bean.UserBean;
import com.demo.mvp.interactor.ILoginInteractor;
import com.demo.mvp.view.LoginView;
import com.demo.mvp.view.OnLoginFinishedListener;

public class LoginPresenter implements ILoginPresenter, OnLoginFinishedListener
{

	private LoginView loginView;
	
	private ILoginInteractor loginInteractor;

	public LoginPresenter(LoginView loginView)
	{
		this.loginView = loginView;
		loginInteractor = IocContainer.getShare().get(ILoginInteractor.class);
	}

	@Override
	public void onUsernameError()
	{
		loginView.setUsernameError();
		loginView.hideProgress();
	}

	@Override
	public void onPasswordError()
	{
		loginView.setPasswordError();
		loginView.hideProgress();
	}

	@Override
	public void onSuccess()
	{
		loginView.hideProgress();
		loginView.navigateToHome();
	}

	/**
	 * 登陆
	 */
	@Override
	public void validateCredentials(String username, String password)
	{
		loginView.showProgress();
		loginInteractor.login(username, password, this);
	}

	/**
	 * 注册
	 */
	@Override
	public void regist(UserBean userBean)
	{
		// TODO Auto-generated method stub
		loginView.showProgress();
		loginInteractor.regist(userBean, this);
	}

}
